<!--{include file="header.html"}-->
<!-- END HEAD -->

<!-- BEGIN BODY -->
<body class="page-header-fixed">
	<!-- BEGIN HEADER -->
	<!--{include file="top.html"}-->
	<!-- END HEADER -->

	<!-- BEGIN CONTAINER -->
	<div class="page-container row-fluid">
		<!-- 左边开始 -->
		<div class="page-sidebar nav-collapse collapse">
			<!-- BEGIN SIDEBAR MENU -->
			<!--{include file="menu.html"}-->
			<!-- END SIDEBAR MENU -->
		</div>
		<!-- 左边结束 -->

		<!-- BEGIN PAGE -->
		<div class="page-content">
			<!-- 右边开始-->
			<div class="container-fluid" >
				<!--右边标题导航开始-->
				<div class="row-fluid">
					<div class="span12">
						<!-- BEGIN PAGE TITLE & BREADCRUMB-->
						<!--{include file="nav.html"}-->
						<!-- END PAGE TITLE & BREADCRUMB-->
					</div>
                   
				<!--右边标题导航结束-->
                <!--右边中介内容开始-->
                <div class="content" >
                    <p class="fl">
                        <!--{if $whether_m}-->
                        <!--{if $is_business}-->
                        <a class="btn green" href="<!--{$url_prefix}-->customer/edit_customer/0">添加</a>
                        <!--{else}-->
                        <a class="btn green" onclick="show_customer(0)">添加</a>
                        <!--{/if}-->
                        <!--{/if}-->
                    </p>
                    <p class="fr">
                        <input id="seek" name="seek" value="输入后请按回车进行搜索" title="输入后请按回车进行搜索" type="text" onkeypress="if(event.keyCode==13){search_customer(this)}" onkeyup="backSearchOrRefresh(this)" onblur="search_customer(this)">
                        类型：<select name="customer_type" id="customer_type" onChange="customer_list_page(1)">
                            <option value="all">全部</option>
                            <option value="on">已关注会员</option>
                            <option value="off">非关注会员</option>
                        </select>
                        <a class="btn blue"<!--{if $customer_list}--> href="/biz/customer/print_excel"<!--{else}-->onclick="alert('没有可导出的信息哦!');"<!--{/if}-->>导出已关注会员</a>
                    </p>
                    <div class="portlet box blue">
                        <!--内容-->
                        <!--表格内容-->
                        <div class="portlet-body fuelux ">
                           <!--商品列表开始-->
                            <div class="catalogue user_msg">
                            <table width="100%">
                                <tbody>
                                    <tr class="big_title">
                                        <td class="id">微信昵称</td>
                                        <td class="id_title">卡号</td>
                                        <td>姓名</td>
                                        <td>手机号</td>
                                        <td>性别</td>
                                        <td>生日</td>
                                        <td>城市</td>
                                        <td>时间</td>
                                        <td>操作</td>
                                    </tr>
                                    <script src="<!--{$url_prefix}-->media/js/jquery-1.10.1.min.js"></script>
                                    <!--{if $customer_list}-->
                                    <!--{foreach from = $customer_list item = cl key = k}-->
                                    <tr<!--{if $k % 2 != 0}--> class="bg"<!--{/if}--> style="line-height:35px">
                                    	<td class="id_title" style="width: 19%">
                                            <div class="fl" style="padding-right: 5px"><!--{if $cl.id_open}--><!--{urldecode($cl.nick_name)}--><!--{/if}--></div>
                                            <!--{if $cl.id_open}--><a href="javascript:void(0)" id="nick<!--{$cl.id_customer}-->" onclick="edit_name(1,<!--{$cl.id_customer}-->)">(<!--{$cl.name_remarks|default:'备注'}-->)</a>
                                            <script type="text/javascript">
                                                var remarks = $('#nick<!--{$cl.id_customer}-->');
                                                var name_remarks = remarks.html();
                                                if((name_remarks.length-2) <= 2){
                                                    remarks.addClass('note_one');
                                                }else if((name_remarks.length-2) <= 4 && (name_remarks.length-2) > 2){
                                                    remarks.addClass('note');
                                                }
                                            </script>
                                            <!--{/if}-->
                                            <input type="hidden" id="id_open<!--{$cl.id_customer}-->" value="<!--{$cl.id_open}-->"/>
                                            <input type="hidden" id="id_customer[]" name="id_customer[]" value="<!--{$cl.id_customer}-->"/>
                                            <div id="editdiv<!--{$cl.id_customer}-->" style="display: none; line-height: 30px;">
                                                <input class="span6 m-wrap" type="text" id="nick_name<!--{$cl.id_customer}-->"/>
                                                <input class="btn blue" type="button" value="确定" onclick="submit_name(<!--{$cl.id_customer}-->,<!--{$offset}-->);"/>
                                                <input class="btn" type="button" value="取消" onclick="edit_name(2,<!--{$cl.id_customer}-->);"/>
                                            </div>
                                        </td>
                                        <td class="id"><!--{$cl.number|sprint_member_card}--></td>
                                        <td><!--{$cl.real_name}--></td>
                                        <td><!--{$cl.cell_phone}--></td>
                                        <td><!--{if $cl.sex == 1}-->男<!--{else}-->女<!--{/if}--></td>
                                        <td><!--{$cl.birthday_month}-->-<!--{$cl.birthday_day}--></td>
                                        <td><!--{$cl.city}--></td>
                                        <td><!--{substr($cl.created,0,10)}--></td>
                                        <td>
                                            <!--{if $is_business}-->
                                            <a href="<!--{$url_prefix}-->customer/edit_customer/<!--{$cl.id_customer}-->">编辑</a>
                                            <!--{else}-->
                                            <a onclick="show_customer(<!--{$cl.id_customer}-->)">编辑</a>
                                            <!--{/if}-->
                                            <a onclick="delete_customer(<!--{$cl.id_customer}-->,<!--{$offset}-->)">删除</a></td>
                                    </tr>
                                    <!--{/foreach}-->
                                    <!--{else}-->
                                    <tr>
                                        <td colspan="8">
                                            还没有会员信息！
                                        </td>
                                    </tr>
                                    <!--{/if}-->
                                </tbody>
                            </table>
                            <!--分页 start-->
                                <!--{if $total}--><div class="fl"><p style="line-height: 50px; padding-left: 10px">共<!--{$total}-->条</p></div><!--{/if}-->
                            <!--{if $page_html}-->
                                <div class="pagination">
                                    <ul>
                                        <!--{$page_html}-->
                                    </ul>
                                </div>
                            <!--{/if}-->
                            <!--分页 ene-->
                            </div>
                            <!--商品列表结束-->
                        </div>
				    </div>
                </div>
                <!--右边中介内容结束-->
			</div>
			<!-- 右边结束-->
		</div>
		<!-- END PAGE -->
	</div>
	<!-- END CONTAINER -->
    <!--编辑会员信息弹出层-->
    <div id="prompt" style="width:800px;top:20%;display: none;">
        <input type="hidden" name="cid"/>
        <div class="title">编辑会员信息<a id="close" onclick="edit_customer('close')">关闭</a></div>
        <div class="content">
            <p><span class="accountinfo_name fl">姓名：</span><input type="text" name="real_name"/></p>
            <p><span class="accountinfo_name fl">手机：</span><input type="text" name="phone"/></p>
            <p><span class="accountinfo_name fl">门店：</span>
                <select name="shop_" id="shop_">
                    <!--{foreach from=$shop_list item= s}-->
                    <option value="<!--{$s.id_shop}-->"><!--{$s.name}--></option>
                    <!--{/foreach}-->
                </select>
            </p>
            <p><span class="accountinfo_name fl">性别：</span><input type="radio" name="sex" value="1" style="margin-top: -1px"/>男<input type="radio" name="sex" value="2" style="margin-top: -1px;margin-left: 20px;"/>女</p>
            <p><span class="accountinfo_name fl">头像：</span>
            <input type="hidden" value="" name="image_src" id="image_src"/>
                <input type="button" id="uploadBtn" value="上传" class="btn blue fl"/>
            <span id="show_customer" style="max-height: 227px;margin-left: 20px;display: inline-block;"></span>
            </p>
            <p><span class="accountinfo_name fl">出生：</span><select name="month" id="month" style="outline: none;">
                    <option value="1">出生月</option>
                    <option value="1">1月</option>
                    <option value="2">2月</option>
                    <option value="3">3月</option>
                    <option value="4">4月</option>
                    <option value="5">5月</option>
                    <option value="6">6月</option>
                    <option value="7">7月</option>
                    <option value="8">8月</option>
                    <option value="9">9月</option>
                    <option value="10">10月</option>
                    <option value="11">11月</option>
                    <option value="12">12月</option>
                </select>
                <select name="days" id="days" style="margin-right:0;outline: none;">
                    <option value="1">出生日</option>
                </select>
            </p>
            <!--<p><span class="accountinfo_name fl">身高：</span><input type="text" name="stature" style="margin-right:10px;"/>cm</p>
            <p><span class="accountinfo_name fl">体重：</span><input type="text" name="body_weight" style="margin-right:10px;"/>kg</p>onblur="get_health_index()"
            <p>健康指数：<input type="text" name="health_index" style="width:220px;margin-right:10px;" onclick="get_health_index()"/>适用18岁至65岁人士,不适用儿童,青少年,孕妇,乳母,老人及运动员等.</p>
            <p>BMI分类&nbsp;&nbsp;&nbsp;&nbsp;中国参考标准<br>
                体重过低	&nbsp;&nbsp;&nbsp;&nbsp;<18.5<br>
                正常范围	&nbsp;&nbsp;&nbsp;&nbsp;18.5～23.9<br>
                肥胖前期	&nbsp;&nbsp;&nbsp;&nbsp;24.0～26.9<br>
                I度肥胖	&nbsp;&nbsp;&nbsp;&nbsp;27～29.9<br>
                II度肥胖	&nbsp;&nbsp;&nbsp;&nbsp;≥30<br>
                Ⅲ度肥胖&nbsp;&nbsp;&nbsp;&nbsp;	≥40</p>
            <p style="height: 160px;"><span class="accountinfo_name fl">培训前：</span><textarea id="before_train" name="before_train" style="width:300px;"></textarea></p>
            <p style="height: 150px;"><span class="accountinfo_name fl">培训后：</span><textarea id="after_train" name="after_train" style="width:300px;"></textarea></p>-->
            <div class="prompt_button fr" style="margin:5px 10px 0 0;padding: 0;">
                <a class="bindeticket" style="margin: 0;background:#35a948" onclick="edit_customer('ok')">确定</a>
            </div>
        </div>
    </div>
    <div id="pop_up" style="display:none"></div>
	<!-- BEGIN FOOTER -->
	<!--{include file="footer.html"}-->
	<!-- END PAGE LEVEL SCRIPTS -->

    <script type="text/javascript" src="<!--{$url_prefix}-->media/js/ajaxupload.js"></script>
    <script src="<!--{$url_prefix}-->media/kindeditor/kindeditor-min.js"></script>
    <script src="<!--{$url_prefix}-->media/kindeditor/lang/zh_CN.js"></script>
    <!--<script src="&lt;!&ndash;{$url_prefix}&ndash;&gt;media/kindeditor/editor.js"></script>-->
<script>
$(function(){
    var url = '<!--{$url_prefix}-->';
    //上传海报图片
    uplodImage('uploadBtn', 'image_src', 'show_customer',url);
    //初始化编辑器
//    editor('before_train','before_train',url);
//    editor('after_train','after_train',url);

//    $('#prompt').hide();
});
    jQuery(document).ready(function() {
       App.init();
       UITree.init();

        $("#month").change(function(){
            var mth = $(this).val();
            if(mth > 0){
                $("#days").empty();
                var optn = '';
                if(mth == 2){
                    optn = create_opentis(29,1);
                }else if(mth == 1 || mth == 3 || mth == 5 || mth == 7 || mth == 8 || mth == 10 || mth == 12){
                    optn = create_opentis(31,1);
                }else{
                    optn = create_opentis(30,1);
                }
                if(mth){
                    $("#days").append(optn);
                }
            }else{
                $("#days").empty();
                $("#days").append('<option value="1">出生日</option>');
            }
        });

    });

    function create_opentis(length,day){
        var optn = '';
        for(var i=1 ;i <= length; i++){
            optn += '<option value="'+i+'"';
            if(i== day){
                optn += ' selected="selected"';
            }
            optn += '>'+i+'日</option>';
        }
        return optn;
    }

    /*
     *  zxx
     *  计算人体健康指数
     *  sex  性别   （1表示男，2表示女）
     *  body_weight  表示人体体重
     *  stature  身高
     */
//    function get_health_index(){
////    BMI适用于18岁至65岁的人士，不适用儿童、青少年、孕妇、乳母、老人及运动员等。
////        体重指数＝体重（公斤）÷身高（米）的平方。
////        体重指数——男性： 体重指数——女性：
////        过轻——低于20        过轻——低于19
////        适中—— 20-25        适中——19-24
////        过重——25-30          过重——24-29
////        肥胖——30-35          肥胖—— 29-34
////        非常肥胖—— 高于35 非常肥胖——高于34
//        var sex = $('input[name="sex"]:checked').val();
//        var body_weight = $('input[name="body_weight"]').val();
//        var stature = $('input[name="stature"]').val();
//        var msg = '';
//        var health_index = (body_weight/(stature*stature))*10000;
//        health_index = health_index.toFixed(1);
//        switch(sex){
//            case '1':
//                if(health_index<20)
//                    msg = "("+health_index+")您的体重过轻，请注意营养！";
//                else
//                if(health_index>=20 && health_index<=25)
//                    msg = "("+health_index+")您的体重很适中！";
//                else
//                if(health_index>25 && health_index<=30)
//                    msg = "("+health_index+")你的体重过重！请注意饮食！";
//                else
//                if(health_index>30 && health_index<=35)
//                    msg ="("+health_index+")你的体重已超重了！请注意减肥！";
//                else
//                if(health_index>35)
//                    msg = "("+health_index+")你的体重已经超重，请注意节食！";
//                break;
//            case '2':
//                if(health_index<19)
//                    msg = "("+health_index+")您的体重过轻，请注意营养！";
//                else
//                if(health_index>=19 && health_index<=24)
//                    msg = "("+health_index+")您的体重很适中！";
//                else
//                if(health_index>24 && health_index<=29)
//                    msg = "("+health_index+")你的体重过重！请注意饮食！";
//                else
//                if(health_index>29 && health_index<=34)
//                    msg = "("+health_index+")你的体重已超重了！请注意减肥！";
//                else
//                if(health_index>34)
//                    msg = "("+health_index+")你的体重已经超重，请注意节食！";
//                break;
//            default:
//                msg = "你没做任何选择！";
//                break;
//        }
//        $('input[name="health_index"]').val(msg);
//    }

    //展示编辑会员信息
    function show_customer(id_customer){
        if(id_customer){
            $.post('<!--{$url_prefix}-->customer/show_customer', {
                'id_customer': id_customer
            }, function(data){
                if(data.error == 1){
                    $('input[name="cid"]').val(data.data.id_customer);
                    $('input[name="real_name"]').val(data.data.real_name);
                    $('input[name="phone"]').val(data.data.cell_phone);
                    $('input[value="'+data.data.sex+'"]').attr('checked','checked');
                    $('#month option[value="'+data.data.birthday_month+'"]').attr('selected','selected');
//                    $('#days option[value="'+data.data.birthday_day+'"]').attr('selected','selected');
//                    $('input[name="stature"]').val(data.data.stature);
//                    $('input[name="body_weight"]').val(data.data.body_weight);

                    var optn = '';
                    var mth_ = data.data.birthday_day;
                    mth_ = mth_?mth_:1;
                    if(mth_ == 2){
                        optn = create_opentis(29,mth_);
                    }else if(mth_ == 1 || mth_ == 3 || mth_ == 5 || mth_ == 7 || mth_ == 8 || mth_ == 10 || mth_ == 12){
                        optn = create_opentis(31,mth_);
                    }else{
                        optn = create_opentis(30,mth_);
                    }
                    if(mth_){
                        $("#days").append(optn);
                    }

                    if(data.data.head_url){
                        var html = '<div><img src="'+data.data.head_url+'" style="width:120px;height:100px;"/><a onclick="delete_img(this)">X</a></div>';
                        $('#show_customer').html(html);
                        $('input[name=image_src]').val(data.data.head_url);
                    }
//                    $('#before_train').html(data.data.train_before);
//                    $('#after_train').html(data.data.train_after);
//                    $('.ke-edit-iframe').first().contents().find('body').html(data.data.train_before);
//                    $('.ke-edit-iframe').last().contents().find('body').html(data.data.train_after);
                }
            }, 'json');
        }

        $('#month option[value="1"]').attr('selected','selected');
        $('input[name="sex"]').first().attr('checked','checked');
        $('#prompt').show();
        $('#pop_up').show();
    }

    //提交编辑会员的信息
    function edit_customer(type){
        if(type == 'close'){
            $('#prompt').hide();
            $('#pop_up').hide();
            $('input[name="image_src"]').val('');
            $('#show_customer').html('');
            return;
        }
        var id_customer = $('input[name=cid]').val();
        var real_name = $('input[name=real_name]').val();
        var phone = $('input[name=phone]').val();
        var shop_ = $('#shop_').val();
        var sex = $('input[name=sex]:checked').val();
        var birthday_month = $('#month').val();
        var birthday_day = $('#days').val();
        var image_src = $('input[name=image_src]').val();
//        var stature = $('input[name=stature]').val();
//        var body_weight = $('input[name=body_weight]').val();
//        var before_train = $('textarea[name=before_train]').val();
//        var after_train = $('textarea[name=after_train]').val();
//        var health_index = $('input[name=health_index]').val();
        $.post('<!--{$url_prefix}-->customer/edit_customer', {
            'id_customer': id_customer,
            'real_name': real_name,
            'phone': phone,
            'shop_':shop_,
            'sex': sex,
            'birthday_month': birthday_month,
            'birthday_day': birthday_day,
            'image_src': image_src,
//            'stature': stature,
//            'body_weight': body_weight,
//            'before_train': before_train,
//            'after_train': after_train
//            'health_index': health_index
        }, function(data){
            $('input[name="image_src"]').val('');
            $('#show_customer').html('');
            window.location.reload();
        });
    }

    //删除会员
    function delete_customer(id_customer,offset){
//        $.post('<!--{$url_prefix}-->customer/delete_customer', {
//            'id_customer': id_customer
//        }, function(data){
//            if(data == 1)
//                window.location.reload();
//            else
//                alert('删除失败。');
//        });
        var search_key = $('#seek').val();
        $.post('<!--{$url_prefix}-->customer/card_list', {
            'ispage': 1,
            'search_key':search_key=='输入后请按回车进行搜索'?'':search_key,
            'customer_type':$('#customer_type').val(),
            'id_customer':id_customer,
            'offset':offset
        }, function(data){
            if(data == '0'){
                alert('删除失败了！');
            }else{
                $('.catalogue').html(data);
            }
        }, 'text');
    }

    function delete_img(obj){
        $(obj).parent().remove();
        $('input[name="image_src"]').val('');
    }


    //搜索提示效果
    $("#seek").click(function(){
        if($(this).val() == $(this).attr('title')){
            $(this).val('');
        }
    }).blur(function(){
        if($(this).val() == ''){
            $(this).val($(this).attr('title'));
        }
    });
    function edit_name(num,id_customer){
        //隐藏已经打开的修改备注名框
        $('input[name="id_customer[]"]').each(function(a){
            var id_customer_msg = $(this).val();
            var num_dis = $('#editdiv'+id_customer_msg);
            if(num_dis.css('display') != 'none'){
                num_dis.slideUp('fast');
                setTimeout(function(){
                    $('#nick'+id_customer_msg).show();
                },300);
            }
        });
        //打开需要修改备注名的框
        if(num == 1){
            if($('#editdiv'+id_customer).css('display') == 'none'){
                $('#editdiv'+id_customer).show();
                $('#nick'+id_customer).hide();
                if($('#nick'+id_customer).text().replace('(','').replace(')','') == '备注'){
                    $('#nick_name'+id_customer).val('');
                }else{
                    $('#nick_name'+id_customer).val($('#nick'+id_customer).text().replace('(','').replace(')',''));
                }
            }else{
                $('#editdiv'+id_customer).hide();
            }
        }else{
            $('#editdiv'+id_customer).hide();
            $('#nick'+id_customer).show();
            $('#nick_name'+id_customer).val('');
        }
    }
    //提交编辑的微信昵称
    function submit_name(id_customer,offset){
        var nick_name = $('#nick_name'+id_customer).val();
        nick_name = nick_name.replace(/(\r)*\n/g,"").replace(/\s/g,"");
        if(nick_name == ''){
            alert('请输入你要修改的昵称！');
            return;
        }else{
            var search_key = $('#seek').val();
            $.post('<!--{$url_prefix}-->customer/edit_name', {
                'nick_name': nick_name,
                'id_open': $('#id_open'+id_customer).val(),
                'search_key':search_key=='输入后请按回车进行搜索'?'':search_key,
                    'customer_type':$('#customer_type').val(),
                'offset':offset,
                'page_type':'customer'
            }, function(data){
                $('.catalogue').html(data);
            }, 'text');
        }
    }

    //物品列表分页
    function customer_list_page(offset){
        var search_key = $('#seek').val();
        $.post('<!--{$url_prefix}-->customer/card_list', {
            'ispage': 1,
            'search_key':search_key=='输入后请按回车进行搜索'?'':search_key,
                'customer_type':$('#customer_type').val(),
            'offset':offset
        }, function(data){
            $('.catalogue').html(data);
        }, 'text');
    }


    //搜索关键字
    function search_customer(obj){
        var search_keys = $(obj).val();
        var search_key = search_keys.replace(/(\r)*\n/g,"").replace(/\s/g,"");
        if(search_key == ''){
//                alert('请输入你要搜索的文字内容！');
            return;
        }else{
            $.post('<!--{$url_prefix}-->customer/search_customer', {
                'ispage': 1,
                'search_key':search_key=='输入后请按回车进行搜索'?'':search_key,
                'customer_type':$('#customer_type').val(),
                'offset':1
            }, function(data){
                $('.catalogue').html(data);
            }, 'text');
        }
    }
    //搜索返回刷新
    function backSearchOrRefresh(obj){
        var searchinput = $(obj).val();
        if(searchinput == ''){
            customer_list_page(1);
        }
    }

//    function editor(name,path,doman){
//        var editor;
//        KindEditor.ready(function(K) {
//            editor = K.create('textarea[name="'+name+'"]', {
//                resizeType : 1,
//                themeType:'default',
//                allowImageUpload : true,
//                uploadJson:doman+'files/upload_all_file/'+path,
//                shadowMode:false,
//                allowMediaUpload:false,
//                afterBlur:function(){
//                    this.sync();
//                    var content = $('#'+name).val();
//                    var num = 0;
//                    if(path == 'before_train'){
//                        if(300 > content.length && content.length > 1){
//                            num = 1;
//                        }
//                    }else if(path == 'after_train'){
//                        if(300 > content.length && content.length > 1){
//                            num = 1;
//                        }
//                    }
//                    if(num == 1){
//                        $('#'+name).parent().children('.help-inline').remove();
//                        $('#'+name).parent().parent().removeClass('error');
//                    }
//                },
//                items : ['emoticons','image','|','link','unlink']
//            });
//        });
//    }

</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>